import router from './router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import store from "./store"
NProgress.configure({ showSpinner: false }) 

const whiteList = ['/login'] 

router.beforeEach(async(to, from, next) => {
  NProgress.start()
  window.document.title = to.meta.title

  const hasToken = store.state.token
  const path = to.path
  if(hasToken){
    next()
  }else{
    if(whiteList.indexOf(path) === -1){
      //不在白名单
      next('/login')
    } else{
      next()
    }
  }

  NProgress.done()
})

router.afterEach(() => {
  NProgress.done()
})
